package com.dlg.commons.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * Xss/sql 过滤 
 * @author mwz
 * @since  2017年6月12日 下午6:58:42
 */
public class XssAndSqlFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		try {
			XssAndSqlHttpServletRequestWrapper xssRequest = new XssAndSqlHttpServletRequestWrapper((HttpServletRequest) request);  
			chain.doFilter(xssRequest, response); 
		} catch (Exception e) {
			response.getWriter().print(e.getMessage());
			response.getWriter().flush();
			response.getWriter().close();
		}
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
	}

}
